package com.njupt.Array;

/**
 * 27. 移除元素。双指针移除指定的元素
 */
public class RemoveElement {


    public int removeElement(int[] nums, int val) {
        int slowIndex = 0;
        for (int fastIndex = 0; fastIndex < nums.length; fastIndex++) {
            if(nums[fastIndex] != val){
                nums[slowIndex++] = nums[fastIndex];
            }
        }
        return  slowIndex;
    }

    public static void main(String[] args) {
        int[] nums = {3,2,2,3};
        RemoveElement test = new RemoveElement();
        System.out.println(test.removeElement(nums, 3));
    }


}
